package com.xlp;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

import java.text.SimpleDateFormat;
import java.util.Date;

public class SendSms {
    private String phone;
    private String random;
    public SendSms(String phone, String random) {
        this.phone=phone;
        this.random=random;
        DefaultProfile profile = DefaultProfile.getProfile("default", "LTAI4GJznwhjGXh37WyqXz7U", "bwdD2Wd7HyXqeVL9wVgxmsA2CCq8tH");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "default");
        request.putQueryParameter("PhoneNumbers", phone);
        request.putQueryParameter("SignName", "电影购票");
        request.putQueryParameter("TemplateCode", "SMS_195575559");
        request.putQueryParameter("TemplateParam",  "{\"code\":\""+random+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
